# -*- coding: utf-8 -*-
"""
part4: 日志系统， 发布-订阅, 选择性订阅子消息
发布
"""

import pika
import sys


connection = pika.BlockingConnection(pika.ConnectionParameters(host='172.22.23.252'))
channel = connection.channel()

channel.exchange_declare(exchange='direct_logs',
                         exchange_type='direct')

severity = sys.argv[1] if len(sys.argv) > 1 else 'info'
message = ''.join(sys.argv[2:]) or 'Hello World!'

channel.basic_publish(exchange='direct_logs',
                      routing_key=severity,
                      body=message)

print("[x] Sent %r:%r" % (severity, message))

connection.close()



